
//
//  DYSearchViewController.m
//  DYHospital
//
//  Created by 胡金东 on 16/3/21.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "DYSearchViewController.h"



@interface DYSearchViewController ()<UISearchBarDelegate>
@property (nonatomic,strong)UISearchBar *searchBar;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIView *topView;
@property (nonatomic,strong)NSMutableArray *searchArr;
@property (nonatomic,assign)BOOL isSearching;


@end

@implementation DYSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _searchBar.delegate = self;
    [self addTopView];
    
}
//自定义取消
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    UIView *view = [_searchBar.subviews objectAtIndex:0];
    for (UIView *subView in view.subviews) {
        if ([subView isKindOfClass:[UIButton class]]) {
            UIButton *cancelButton = (UIButton *)subView;
            [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
            [cancelButton addTarget:self action:@selector(onBack) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    
}


-(void)onBack
{
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    [self.searchBar becomeFirstResponder];
    self.navigationController.navigationBar.hidden = YES;
}
-(void)addTopView
{
    _topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    _topView.backgroundColor = [UIColor whiteColor];
    _searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
    [_searchBar setTintColor:[UIColor blackColor]];
    [_searchBar setBarTintColor:[UIColor lightGrayColor]];
    _searchBar.searchBarStyle = UISearchBarStyleDefault;
    _searchBar.backgroundImage = [UIImage imageNamed:@"searchBar_Back"];
    _searchBar.placeholder = @"搜索医生、科室、疾病";
    _searchBar.showsCancelButton = YES;
    [_topView addSubview:_searchBar];
    [self.view addSubview:_topView];
    
}


-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [self searchInKeyWord:_searchBar.text];
    [_searchBar resignFirstResponder];
}

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    if ([_searchBar.text isEqualToString:@""]) {
        _isSearching = NO;
//        [self.tableView reloadData];
        return ;
    }
    [self searchInKeyWord:_searchBar.text];
}

-(void)searchInKeyWord:(NSString *)word
{
    _isSearching = YES;
//    _searchArr = 
}

@end
